//
//  WAOderTableHeadView.m
//  WalkiOS
//
//  Created by luqiuan on 2019/10/13.
//  Copyright © 2019 Chenmuzhou. All rights reserved.
//

#import "WAOderTableHeadView.h"
#import "BezierCurveView.h"

@interface WAOderTableHeadView ()
@property (strong,nonatomic)BezierCurveView *bezierView;
@property (strong,nonatomic)NSMutableArray *x_names;
@property (strong,nonatomic)NSMutableArray *targets;
@end

@implementation WAOderTableHeadView
/**
 *  X轴值
 */
-(NSMutableArray *)x_names{
    if (!_x_names) {
        _x_names = [NSMutableArray new];
//        _x_names = [NSMutableArray arrayWithArray:@[@"09-8 23:43",@"09-8 23:43",@"09-8 23:43",@"09-8 23:43",@"09-8 23:43"]];
    }
    return _x_names;
}
/**
 *  Y轴值
 */
-(NSMutableArray *)targets{
    if (!_targets) {
        _targets = [NSMutableArray new];
//        _targets = [NSMutableArray arrayWithArray:@[@20,@40,@20,@50,@30,@90,@30,@100,@70]];
    }
    return _targets;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self = [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] firstObject];
        self.frame = frame;
        
        
        self.textFiled.returnKeyType = UIReturnKeySearch;//变为搜索按钮
    }
    return self;
}

- (void)configWithTenModel:(NSArray *)tenList totalModel:(WATransactionTotalDataModel *)totalModel{
    self.minLB.text = [NSString stringWithFormat:@"￥%.2f",totalModel.lowData];
    self.maxLB.text = [NSString stringWithFormat:@"￥%.2f",totalModel.highData];
    self.currentLB.text = [NSString stringWithFormat:@"￥%.2f",totalModel.nowData];
    self.completeLB.text = [NSString stringWithFormat:@"%.0f",totalModel.totalData];
    self.buyLB.text = [NSString stringWithFormat:@"%.0f",totalModel.readyTotalData];
    self.updownLB.text = [NSString stringWithFormat:@"%.2f%%",totalModel.raiseData];
    
    [self.x_names removeAllObjects];
    [self.targets removeAllObjects];
    tenList = [[tenList reverseObjectEnumerator] allObjects];
    
    CGFloat maxValue = 0;
    
    for (WATransactionTenDataModel *model in tenList) {
        NSString * mouthStr = [model.date substringWithRange:NSMakeRange(4, 2)];
        NSString * dayStr = [model.date substringWithRange:NSMakeRange(6, 2)];
        [self.x_names addObject:[NSString stringWithFormat:@"%@-%@",mouthStr,dayStr]];
        [self.targets addObject:@(model.data)];
        if (maxValue < model.data) {
            maxValue = model.data;
        }
    }
    if (self.targets.count == 0) {
        return;
    }
    
    if (_bezierView) {
        [_bezierView removeFromSuperview];
        _bezierView = nil;
    }
    
    //1.初始化
    _bezierView = [BezierCurveView initWithFrame:CGRectMake(10, 110, WNScreenWidth-10, 280)];
    [self addSubview:_bezierView];
    //曲线
    [_bezierView drawLineChartViewWithX_Value_Names:self.x_names TargetValues:self.targets LineType:LineType_Straight max:maxValue];
}

@end
